package com.cnap.multiclouldmgmt.util;

import com.alibaba.fastjson.JSONObject;
import com.cnap.multiclouldmgmt.model.CommonResult;
import com.fasterxml.jackson.core.type.TypeReference;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

class JsonUtilTest {

    private static Map<String, String> testData = new HashMap<>();
    static {
        testData.put("a","b");
        testData.put("c","d");
    }

    @Test
    void objectToJsonStr() {
        JsonUtil.objectToJsonStr(testData);
    }

    @Test
    void jsonStrToObject() {

        JsonUtil.jsonStrToObject(JsonUtil.objectToJsonStr(testData), Map.class);

    }

    @Test
    void testJsonStrToObject() {

        CommonResult<String> testData = new CommonResult<>();
        testData.setData("aaaaaaaaaaa");
        JsonUtil.jsonStrToObject(JsonUtil.objectToJsonStr(testData),
                new TypeReference<CommonResult<String>>() {
        });
    }

    @Test
    void getValueFromJsonStr() {
        String str = JSONObject.toJSONString(testData);
        JsonUtil.getValueFromJsonStr(str,"a");
        JsonUtil.getValueFromJsonStr(str,"h");

    }

    @Test
    void testObjectToJsonStr() {
    }

    @Test
    void testJsonStrToObject1() {
    }

    @Test
    void testJsonStrToObject2() {
    }

    @Test
    void testGetValueFromJsonStr() {
    }
}